package com.jinghua.treatment.wechat.controller;

import com.alibaba.fastjson.JSONObject;
import com.jinghua.treatment.common.GlobalConstant;
import com.jinghua.treatment.common.controller.BaseController;
import com.jinghua.treatment.common.domain.JSONResult;
import com.jinghua.treatment.common.exception.BizException;
import com.jinghua.treatment.service.SysDoctorService;
import com.jinghua.treatment.tools.IDGenerator;
import com.jinghua.treatment.tools.PropertyUtil;
import com.jinghua.treatment.wechat.biz.SMSBiz;
import com.jinghua.treatment.wechat.biz.WechatBiz;
import com.jinghua.treatment.wechat.entity.WXJSConfig;
import com.jinghua.treatment.wechat.util.HttpUtil;
import com.jinghua.treatment.wechat.util.WechatUtil;
import io.swagger.annotations.ApiOperation;
import org.dom4j.Document;
import org.dom4j.DocumentException;
import org.dom4j.io.SAXReader;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.util.StringUtils;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.Date;

/**
 * 专门处理发送短信
 */
@Controller
@RequestMapping("/sms")
public class SMSController extends BaseController{



    @ApiOperation(value="发送短信")
    @RequestMapping(value="/send")
    @ResponseBody
    public JSONResult sms(String phone) {
        if(StringUtils.isEmpty(phone))
            throw new BizException("电话不能为空！");
        String regCode = smsBiz.sendSMSValicode(phone);
        // TODO 需要加过期时间
        session.setAttribute("regSMS", regCode);
        return jsonResult(GlobalConstant.SUCCESS_CODE, "ok", null);
    }

    @Autowired
    private SMSBiz smsBiz;

}
